$(function(){
	
	var baseUrl = $("base").attr("href");
	
	/**加载地图*/
	function InitMap(){
		var map = new BMap.Map("Map");
		var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
		var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
		map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
		map.enableContinuousZoom();  
		map.centerAndZoom(new BMap.Point(116.404, 39.915), 15);
		map.addControl(top_left_control);        
		map.addControl(top_left_navigation);  
		$.getJSON("http://api.map.baidu.com/geocoder/v2/?address="+ $("#estateAddress").text() +"&output=json&ak=n7mTxnHfQyF2MG5CN76ZXe7z&callback=?",function(data){
			var point =  new BMap.Point(data.result.location.lng, data.result.location.lat);

				var marker = new BMap.Marker(point);  // 创建标注
				map.addOverlay(marker);              // 将标注添加到地图中
			
			map.panTo(point);
		});
	}
	
	
		
	//从from获取数据，转为对象  
	function fromToJson(form) {  
	    var result = {};  
	    var fieldArray = $('#' + form).serializeArray();  
	    for (var i = 0; i < fieldArray.length; i++) {  
	        var field = fieldArray[i];  
	        if (field.name in result) {  
	            result[field.name] += ',' + field.value;  
	        } else {  
	            result[field.name] = field.value;  
	        }  
	    }  
	    return result;  
	}  
	
	
	$("#schedual-submit").click(function(){
		$.ajax({
			url :　baseUrl + "user/json-addSchedual.do",
			method : "post",
			data : fromToJson("schedual-form"),
			success : function(data){
				if(data.code == 1000){
					sweetAlert({
						title:"预订成功",
						text:"您的预订信息已存储，请等待房主联系",
						type:"success",
					});
				}else{
					console.log("sechedualErroe",data);
					sweetAlert({
						title:"预订失败",
						text:"您的预订出错,原因是" + data.data,
						type:"error",
					});
				}
			},
			error : function(){
				sweetAlert({
						title:"预订失败",
						text:"连接服务器失败",
						type:"error",
					});
			},
			
		});
	});
	
	
	
	
	
	
	
	
	InitMap();
});